<?php
/**
 * Created by jinqiang on 2024/7/18 15:31.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Produce;


use App\Http\Controllers\Controller;
use App\Http\Services\Produce\RfidService;
use Illuminate\Http\Request;

class RfidController extends Controller
{
    public function list(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required',
            'processing_code' => 'required',
            'sku_code' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->search($param);
        return result($res);
    }

    public function search(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'number' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->getNumber($param['number']);
        return result($res);
    }

    //增裁列表
    public function addList(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->searchAdd($param);
        return result($res);
    }

    //作废列表
    public function cancelList(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->searchCancel($param);
        return result($res);
    }

    //作废审核
    public function cancelCheck(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'id' => 'required',
            'status' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->chancelCheck((Int)$param['id'], (Int)$param['status']);
        return $res['code'] === 0 ? success("审核成功") : error($res['msg'], $res);
    }

    //打印列表
    public function printList(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->searchPrint($param);
        return result($res);
    }

    public function count(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
        'processing_code' => 'required',
        'sku_code' => 'required'
    ]);
        $param = $request->all();
        $res = $rfidService->count($param['processing_code'], $param['sku_code']);
        return result($res);
    }

    //补码
    public function add(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'processing_code' => 'required',
            'sku_code' => 'required',
            'num' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->add($param['processing_code'], $param['sku_code'], (Int)$param['num']);
        return $res['code'] === 0 ? success("补码成功") : error($res['msg'], $res);
    }

    //作废
    public function del(Request $request, RfidService $rfidService)
    {
        $this->validate($request, [
            'processing_code' => 'required',
            'sku_code' => 'required',
            'num_1' => 'required',
            'num_2' => 'required'
        ]);
        $param = $request->all();
        $res = $rfidService->del($param['processing_code'], $param['sku_code'], (Int)$param['num_1'], (Int)$param['num_2']);
        return $res['code'] === 0 ? success("作废成功") : error($res['msg'], $res);
    }
}
